package com.ruoyi.project.mgr.room.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.mgr.room.domain.MgrRoom;
import com.ruoyi.project.mgr.room.service.IMgrRoomService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 教室Controller
 * 
 * @author .
 * @date 2020-02-11
 */
@Controller
@RequestMapping("/mgr/room")
public class MgrRoomController extends BaseController
{
    private String prefix = "mgr/room";

    @Autowired
    private IMgrRoomService mgrRoomService;

    @GetMapping()
    public String room()
    {
        return prefix + "/room";
    }

    /**
     * 查询教室列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(MgrRoom mgrRoom)
    {
        startPage();
        List<MgrRoom> list = mgrRoomService.selectMgrRoomList(mgrRoom);
        return getDataTable(list);
    }

    /**
     * 导出教室列表
     */
    @Log(title = "教室", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(MgrRoom mgrRoom)
    {
        List<MgrRoom> list = mgrRoomService.selectMgrRoomList(mgrRoom);
        ExcelUtil<MgrRoom> util = new ExcelUtil<MgrRoom>(MgrRoom.class);
        return util.exportExcel(list, "room");
    }

    /**
     * 新增教室
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存教室
     */
    @Log(title = "教室", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(MgrRoom mgrRoom)
    {
        return toAjax(mgrRoomService.insertMgrRoom(mgrRoom));
    }

    /**
     * 修改教室
     */
    @GetMapping("/edit/{roomId}")
    public String edit(@PathVariable("roomId") Long roomId, ModelMap mmap)
    {
        MgrRoom mgrRoom = mgrRoomService.selectMgrRoomById(roomId);
        mmap.put("mgrRoom", mgrRoom);
        return prefix + "/edit";
    }

    /**
     * 修改保存教室
     */
    @Log(title = "教室", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(MgrRoom mgrRoom)
    {
        return toAjax(mgrRoomService.updateMgrRoom(mgrRoom));
    }

    /**
     * 删除教室
     */
    @Log(title = "教室", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(mgrRoomService.deleteMgrRoomByIds(ids));
    }

    /**
     * 修改状态
     */
    @PostMapping( "/changeStatus")
    @ResponseBody
    public AjaxResult changeStatus(MgrRoom room)
    {
        // 排课表查询
        if (room.getStatus() == 1) {

        }
        return toAjax(mgrRoomService.updateMgrRoom(room));
    }
}
